import request from '../utils/request'

/**
 *  获取轮播图
 * @param pageNum 轮播图页码
 * @param pageSize 轮播图个数
 * @returns {*} 轮播图数据
 */
export function getSwiper(pageNum,pageSize) {
    let params = new URLSearchParams()
    params.append('pageNum', pageNum)
    params.append('pageSize', pageSize)
    const url = `/api/api/cms/article/open/banner/list`
    return request.post(url, params);
}

/**
 *  获取分类列表
 * @param pageSize 下拉列表
 * @returns {*} 下拉列表数据
 */
export function getClassification(pageSize) {
    let params = new URLSearchParams()
    params.append('pageSize', pageSize)
    const url = `/api/api/cms/category/open/list`
    return request.post(url, params);
}

/**
 *  获取新闻列表
 * @param pageNum 轮播图页码
 * @param pageSize 轮播图个数
 * @returns {*} 轮播图数据
 */
export function getNewsList(pageNum,pageSize,categoryId) {
    let params = new URLSearchParams()
    params.append('pageNum', pageNum)
    params.append('pageSize', pageSize)
    params.append('categoryId', categoryId)
    const url = `/api/api/cms/article/open/list`
    return request.post(url, params);
}

/**
 *  获取天气
 * @param city 城市
 * @param key key
 * @returns {*} 天气
 */

export function getWeather(city,key) {
    const url = `simpleWeather/query?city=${city}&key=${key}`
    return request.get(url);
}

/**
 *  获取新闻详情
 * @param articleId id
 * @returns {*} 新闻详情
 */

export function getNewsContent(articleId) {
    const url = `/api/api/cms/article/open/detail/${articleId}`
    return request.get(url);
}

/**
 *  获取搜索内容
 * @param pageNum 搜索页码
 * @param pageSize 搜索个数
 *  @param title  搜索内容
 * @returns {*} 搜索到的内容
 */
export function getSearch(pageNum,pageSize,title) {
    let params = new URLSearchParams()
    params.append('pageNum', pageNum)
    params.append('pageSize', pageSize)
    params.append('title', title)
    const url = `/api/api/cms/article/open/list`
    return request.post(url, params);
}

/**
 *  获取热门新闻列表
 * @param pageNum 页码
 * @param pageSize 个数
 * @returns {*} 热门新闻列表
 */
export function getHot(pageNum,pageSize) {
    let params = new URLSearchParams()
    params.append('pageNum', pageNum)
    params.append('pageSize', pageSize)
    const url = `/api/api/cms/article/open/hot/list`
    return request.post(url, params);
}

/**
 *  点赞
 * @param articleId id
 * @returns {*} 0
 */

export function dianZan(articleId) {
    const url = `/api/api/cms/article/add/zan/${articleId}`
    return request.get(url);
}

/**
 *  增加阅读量
 * @param articleId id
 * @returns {*} 0
 */

export function addRead(articleId) {
    const url = `/api/api/cms/article/open/add/read-num/${articleId}`
    return request.get(url);
}

/**
 *  收藏文章
 * @param articleId id
 * @returns {*} 0
 */

export function collectNews(articleId) {
    const url = `/api/api/cms/collect/collect/article/${articleId}`
    return request.get(url);
}

/**
 *  订阅文章
 * @param categoryIds 分类id
 * @returns {*} 0
 */

export function subNews(categoryIds) {
    let params = new URLSearchParams()
    params.append('categoryIds', categoryIds)
    // params.append('pageSize', pageSize)
    const url = `/api/api/cms/userCategory/subscription/category`
    return request.post(url, params);
}

/**
 *  订阅文章列表
 * @param articleId id
 * @returns {*} 0
 */

export function subNewsList() {
    const url = `/api/api/cms/category/subscription/list`
    return request.get(url);
}